require('../../assets/css/reset.css')
require('../../assets/css/normalize.css')
require('../../assets/iconf/iconfont.css')
require('./dedail.less')

let axios = require('axios')
// 获取登录时储存的用户信息
let user = JSON.parse(localStorage.getItem('login'))

// 设置axios请求头,添加token
axios.defaults.headers.authorization = "Bearer " + user.token;

let name = document.querySelector('#name')
let longText = document.querySelector('.longText')
let imgUrl = document.querySelector('#imgUrl')
let titleNumk = document.querySelector('.titleNumk')
let titleMin = document.querySelector('.titleMin')
let peoplenum = document.querySelector('#peoplenum')
let frequency = document.querySelector('#frequency')
let qixie = document.querySelector('#qixie')
let btn = document.querySelector('.btn')
let zuo = document.querySelector('#zuo')
let id = location.search.slice(1)

axios.get('http://47.96.154.185:3701/api/train/courseDetail',{
    params:{
        id:id
    }
})
.then(function(res){
    console.log(res);
    if(res.data.errno == 0){
        // 将视频数据转换为JSON字符串传进本地，不转字符串就会被破坏掉
        localStorage.setItem('fragments',JSON.stringify(res.data.data.fragments))
        name.textContent = res.data.data.name
        longText.textContent = res.data.data.desc
        imgUrl.src ='http://47.96.154.185:3701' + res.data.data.imgurl
        titleNumk.textContent = res.data.data.calorie
        titleMin.textContent = res.data.data.time
        peoplenum.textContent = res.data.data.peoplenum
        frequency.textContent = res.data.data.frequency
        qixie.textContent = res.data.data.instrument
    }
})


btn.addEventListener('click',function(){
    location.href = './play.html'
})

imgUrl.addEventListener('click',function(){
    location.href = './play.html'
})

zuo.addEventListener('click',function(){
    location.href = './exercise.html'
})